package cn.edu.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * 1、加载驱动
 * 2、建立连接
 * 3、创建statement对象
 * 4、执行SQL
 * 5、返回执行的结果
 * 6、关闭资源
 */

public class JdbcDemo03 {
    static String url = "jdbc:mysql://localhost:3306/tedu?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true";
    static String user = "root";
    static String password = "root";

    public static void main(String[] args) {
        try {
//            Class.forName("com.mysql.cj.jdbc.Driver");
//            System.out.println("驱动加载成功~~~");
            Connection conn = DriverManager.getConnection(url,user,password);
            System.out.println(conn);
            System.out.println("与数据库建立好连接了~~");

            Statement st = conn.createStatement();
            String sql = "create table mydb02(id int primary key auto_increment," +
                    "username varchar(30)," +
                    "password varchar(30)," +
                    "nickname varchar(30)," +
                    "age int)";
            int rows = st.executeUpdate(sql);
            System.out.println("受影响的行：" + rows);
            conn.close();
            System.out.println("表创建成功了~~");
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
